#include "smallwidget.h"
#include <QSpinBox>
#include <QHBoxLayout>
#include <QSlider>

SmallWidget::SmallWidget(QWidget *parent) : QWidget(parent)
{

    // 创建控件对象
    QSpinBox *spin = new QSpinBox(this);    // 选值框
    QSlider *slider = new QSlider(Qt::Horizontal, this);    // 滑块

    // 将控件添加到布局中
    QHBoxLayout *hLayout = new QHBoxLayout(this);
    hLayout->addWidget(spin);
    hLayout->addWidget(slider);

    // 选值框改变使得滑块值改变
    connect(spin, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
        slider,
        &QSlider::setValue
    );
    // 滑块值改变使得选值框改变
    connect(slider, QSlider::valueChanged, spin, &QSpinBox::setValue);
}
